#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5+10;
const int mod = 10007;

int l,top1,top2;
char s[MAXN],a[MAXN<<1],b[MAXN<<1];
long long f[MAXN<<1][2];

int main (){
	scanf("%d %s",&l,s+1);
	a[++top1] = '_';
	for(int i = 1;i <= l;i++){
		if(s[i] == '(' || s[i] == '*') b[++top2] = s[i];
		if(s[i] == ')')	{while(b[top2] != '(') a[++top1] = b[top2--];top2--;}
		if(s[i] == '+') {while(b[top2] == '*') a[++top1] = b[top2--];b[++top2] = '+';}
		if(s[i] != '(' && s[i] != ')') a[++top1] = '_';
	}
	while(top2>0) a[++top1] = b[top2--];
	for(int i = 1;i <= top1;i++){
		if(a[i] == '*'){
			int f0 = f[top2][0],f1 = f[top2][1],g0 = f[--top2][0],g1 = f[top2][1];
			f[top2][0] = (f0 * (g0 + g1) + f1 * g0)%mod; f[top2][1] = (f1 * g1) % mod;
		}else if(a[i] == '+'){
			int f0 = f[top2][0],f1 = f[top2][1],g0 = f[--top2][0],g1 = f[top2][1];
			f[top2][0] = (f0 * g0)%mod; f[top2][1] = (f1 * (g0 + g1) + f0 * g1) % mod;
		}else{
			f[++top2][0] = 1;f[top2][1] = 1;
		}
	}
	printf("%lld\n",f[1][0]);return 0;
}
			
